import QQMap from '../../../utils/qqmap'
Page({
  data: {
    points: [],
    location: ''
  },
  onShow () {
    this.getLocation()
  },
  async getLocation () {
    const { latitude, longitude } = await wx.getLocation()
    this.getPoint(latitude, longitude)
    this.reverseGeocoder(latitude, longitude)
  },
  getPoint (latitude, longitude) {
    QQMap.search({
      keyword: '足疗',
      location: { latitude, longitude },
      page_size: 10,
      success: result => {
        const points = result.data.map(({ id, title, _distance }) => ({ id, title, _distance }))
        this.setData({ points })
      }
    })
  },
  reverseGeocoder (latitude, longitude) {
    QQMap.reverseGeocoder({
      location: { latitude, longitude },
      success: res => {
        this.setData({ location: res.result.address })
      }
    })
  },
  async chooseLocation () {
    const { latitude, longitude, name } = await wx.chooseLocation()
    console.log(name)
    this.getPoint(latitude, longitude)
    this.setData({ location: name })
  }
})
